import java.util.*;

//SinglyLinkedList 单链表
public class Main {
    static int head = -1,idx=1;
    static int[] e = new int[10010],ne=new int[10010];
    static void pushFront(int x) {
        e[idx]=x;
        ne[idx]=head;
        head = idx;
        idx++;
    }
    static void clear(){
        head=-1;
    }
    static void deleteKthNum(int k){
        if(k==0)clear();
        else ne[k]=ne[ne[k]];
    }
    static void insertAfterKthNum(int k, int x) {
        e[idx]=x;
        ne[idx]=ne[k];
        ne[k]=idx;
        idx++;
    }
    static void printList()
    {
        for(int i=head;i!=-1;i=ne[i])
        {
            System.out.print(e[i]+" ");
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        while(m-->0)
        {
            String op = sc.next();
            switch (op) {
                case "H":
                    pushFront(sc.nextInt());
                    break;
                case "D":
                    deleteKthNum(sc.nextInt());
                    break;
                case "I":
                    insertAfterKthNum(sc.nextInt(), sc.nextInt());
                    break;
            }
        }
        printList();
    }
}